package com.example.administrator.myapplication.util;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by Administrator on 2020/12/7.
 */
//sp工具类
public class SpSave {

    //保存数据 第一个参数上下文，第二个参数 key ，第三个参数value;
    public static boolean saveString(Context context,String key,String value){
        SharedPreferences sharedPreferences =context.getSharedPreferences("data",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor =sharedPreferences.edit();
        editor.putString(key,value);
        editor.commit();
        return true;
    }
    //获取数据第一个参数上文，第二个参数key\
    public static String getSaveString(Context context,String key){
        SharedPreferences sharedPreferences = context.getSharedPreferences("data",Context.MODE_PRIVATE);
        String vaule=sharedPreferences.getString(key,"暂无数据");
        return vaule;
    }
}
